<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.kaishengit.entity.User" %>
<!DOCTYPE HTML>
<html lang="en">
  <head>
 
    <title>My JSP 'newproject.jsp' starting page</title>
    
    <link rel="stylesheet" href="css/bootstrap.min.css" />
	<script type="text/javascript"src="js/jquery.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	
	<style type="text/css">
		a:hover{
			text-decoration:none;
		}
	</style>

  </head>
  
  <body>
  
  	<div class="navbar">
		<div class="navbar-inner">
			<div class="container">
				 
				<!-- .btn-navbar is used as the toggle for collapsed navbar content -->
				<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
				</a>
				 
				<!-- Be sure to leave the brand out there if you want it shown -->
				<a class="brand" href="#">欢迎使用PM系统</a>
				<ul class="nav" >
					<li style="margin-left:40px;">
						<a href="personmanager.jspx">成员管理</a>
					</li>
					<li class="active"><a href="newproject.jspx" style="margin-left:40px;">新建项目</a></li>
					<li><a href="projectlistview.jspx" style="margin-left:40px;">项目列表</a></li>
					<li><a href="#" style="margin-left:40px;">我的任务</a></li>
					<li><a href="#" style="margin-left:40px;">附加功能</a></li>
				</ul>
				 
				<!-- Everything you want hidden at 940px or less, place within here -->
				<ul class="nav pull-right">
					<li>
						<a href="#">欢迎您：</a>
					</li>
					<li class="divider-vertical"></li>
					<li style="margin-top:10px;"><%=((User)session.getAttribute("session_user")).getUsername() %></li>
				</ul>
			</div>
		</div>
    </div>
    
    
    
    
    
    <div class="container" style="margin-left:200px;width:800px;">
		<form class="well" id="newproject" action="newprojectadd.jspx" method="post" >
		<%
			String state = (String)request.getAttribute("state");
			String msg = "";
			if("10001".equals(state)) {
				msg = "添加项目成功";
		%>
		 <div id="msgerror" class="alert alert-error">
	    	<%=msg%>
	    </div>
		
		<%}else if("10002".equals(state)) {
			msg="项目名已经存在";
		%>
		 <div id="msgerror" class="alert alert-error">
	    	<%=msg%>
	    </div>
		<%} %>
		
		    <ul class="breadcrumb">
				<li>
				<a href="#">新建项目</a>
				</li>
				
			</ul>
		
		<label>项目名称</label>
		<input id="projectname" type="text" class="span3" name="projectname">
		
		<label class="control-label" for="textarea">项目描述</label>
		<div class="controls">
		<textarea id="projectdesc" id="textarea" class="input-xlarge" rows="3" name="projectdesc"></textarea>
		</div>
		
		
		<label class="control-label">负责人</label>
		<select class="span2" name="manager">
			<%
				List<User> list = (List<User>)request.getAttribute("list");
				for(User user:list) {
				
			%>
                <option><%=user.getUsername() %></option>
            <%} %>   
        </select>
		<br/>
		
		
		
		
		<select id="select_id" id="multiSelect" multiple="multiple">
			<%
				
				for(User user:list) {
			%>
                <option><%=user.getUsername() %></option>
            <%
				}
            %>    
               
        </select>
		
		<input type="button" id="add" value="添加" />
		<input type="button" id="delete" value="删除" />	
		
		<select id="select_idd" name="worker" id="multiSelect" multiple="multiple">
                
        </select>
		
		<br/>
		
		<div id="msgcheck" class="alert alert-error"> 
	    </div>
		
		
		<button type="submit" class="btn btn-success" >保存</button>
		
	</form>
	
	
	<script type="text/javascript">
		var add = document.getElementById("add");
		var deletea = document.getElementById("delete");
		
		var projectname = document.getElementById("projectname");
		var projectdesc = document.getElementById("projectdesc");
		var msgerror = document.getElementById("msgerror");
		
		var projectname = document.getElementById("projectname");
		var projectdesc = document.getElementById("projectdesc");
		var msgcheck = document.getElementById("msgcheck");
		
		
		msgcheck.style.display="none";
		
		document.getElementById("newproject").onsubmit=function() {
			if(projectname.value=="" || projectdesc.value=="") {
				msgcheck.style.display="block";
				msgcheck.innerHTML="不能为空";
				return false;
			}
			
		};
		
		
		
		
		
		
		
		add.onclick = function() {
			var obj = document.getElementById("select_id"); //selectid
			var objadd = document.getElementById("select_idd");

			var index = obj.selectedIndex; // 选中索引
			
			var varitem = new Option(obj.options[index].text);
			for(var i=0;i<objadd.length;i++) {
				if(objadd.options[i].text==obj.options[index].text) {
					return;
				}
			}
			objadd.appendChild(varitem);
			
		};
		
		deletea.onclick = function() {
			var objadd = document.getElementById("select_idd");
			var index = objadd.selectedIndex; // 选中索引
			objadd.removeChild(objadd.options[index]);
			
		};
		
		
		
		projectname.onfocus = function() {
			msgcheck.style.display="none";
			if(msgerror!=null && msgerror.innerHTML!=""){
				msgerror.style.display="none";
			}	
			
		}
		
		
		projectdesc.onfocus = function() {
			msgcheck.style.display="none";
			if(msgerror!=null && msgerror.innerHTML!="")
			msgerror.style.display="none";
			
		}
	</script>
	
	
	
	  
	</div>
   
  </body>
</html>
